#include "../../../shared/dal/search_repo.hpp"
#include <gflags/gflags.h>
#include <memory>

DEFINE_bool(run_mode, false, "程序的运行模式: false-调试 true-发布");
DEFINE_string(log_file, "", "发布模式下，用于指定日志的输出文件");
DEFINE_int32(log_level, 0, "发布模式下，用于指定日志输出等级");

DEFINE_string(es_host, "http://127.0.0.1:9200/", "es服务器URL");

int main(int argc, char* argv[])
{
    google::ParseCommandLineFlags(&argc, &argv, true);
    shared::init_logger(FLAGS_run_mode, FLAGS_log_file, FLAGS_log_level);

    auto esClient = shared::dal::ESClientFactory::create({FLAGS_es_host});

    auto esUser = std::make_shared<shared::dal::UserSearch>(esClient);

    // esUser->createIndex();
    
    // esUser->appendData("user-1", "小美", "11122233366", "我是小美", "小美头像");
    // esUser->appendData("user-2", "小帅", "11122233399", "我是小帅", "小帅头像");
    // esUser->appendData("user-3", "小丑", "11122233300", "我是小丑", "小丑头像");

    // 添加完立即查找可能查不到, 这时候的数据可能还没到es服务器上
    auto users = esUser->search("小", {"user-3"});    
    for (auto& u : users) {
        std::cout << "-----------------" << '\n';
        std::cout << u.userId() << '\n';
        std::cout << u.phone() << '\n';
        std::cout << u.nickname() << '\n';
        std::cout << u.description() << '\n';
        std::cout << u.avatarId() << '\n';
    }

    return 0;
}